<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>

<form:form commandName="customerDto" cssClass="well form-horizontal">
	<div class="row-fluid">
		<!-- id -->
		<div class="control-group">
		   	<label class="control-label"><spring:message code="customer.field.id" /></label>
		   	<div class="controls">
		   		<input name="id" value='<c:out value="${customerDto.id}"/>' placeholder="<spring:message code="customer.field.id" />" class="input-small disabled" disabled="disabled"/>
	   		</div>
		</div>
		
		<!-- title -->
		<c:set var="titleErrors"><form:errors path="title"/></c:set>
		<div class="control-group <c:if test="${not empty titleErrors}">error</c:if>">
			<label class="control-label"><spring:message code="customer.field.title" /></label>
			<div class="controls">
			    <c:forEach var="title" items="${titles}" >
			    	<label class="radio"> 
			    		<input name="title" type="radio" value="${title}" <c:if test="${customerDto.title eq title}">checked="checked"</c:if>>
			    		<spring:message code="enum.title.${title}" />
					</label>
	    		</c:forEach>
	    		<form:errors path="title" cssClass="help-inline"/>
			</div>
		</div>

		<!-- name -->
		<c:set var="nameErrors"><form:errors path="name"/></c:set>
		<div class="control-group <c:if test="${not empty nameErrors}">error</c:if>">
		   	<label class="control-label"><spring:message code="customer.field.name" /><spring:message code="common.mandatory" /></label>
		   	<div class="controls">
		   		<input name="name" value='<c:out value="${customerDto.name}"/>' placeholder="<spring:message code="customer.field.name" />" />
		   		<form:errors path="name" cssClass="help-inline"/>
	   		</div>
		</div>
		
		<!-- firstname -->
		<c:set var="firstnameErrors"><form:errors path="firstname"/></c:set>
		<div class="control-group <c:if test="${not empty firstnameErrors}">error</c:if>">
		   	<label class="control-label"><spring:message code="customer.field.firstname" /></label>
		   	<div class="controls">
		   		<input name="firstname" value='<c:out value="${customerDto.firstname}"/>' placeholder="<spring:message code="customer.field.firstname" />" />
		   		<form:errors path="firstname" cssClass="help-inline"/>
	   		</div>
		</div>
	</div>

    <div class="alert alert-info">
    	<spring:message code="common.mandatory.explain" />
    </div>

	<div class="form-actions">
		<c:if test="${empty customerDto.id}">
			<sec:authorize access="hasRole('PERM_CREATE_CUSTOMER')">
				<button class="btn btn-primary" type="submit"><spring:message code="common.btn.save" /></button>
				<button class="btn" type="reset"><spring:message code="common.btn.reset" /></button>
			</sec:authorize>
		</c:if>
		<c:if test="${not empty customerDto.id}">
			<sec:authorize access="hasRole('PERM_MODIFY_CUSTOMER')">
				<button class="btn btn-primary" type="submit"><spring:message code="common.btn.save" /></button>
				<button class="btn" type="reset"><spring:message code="common.btn.reset" /></button>
			</sec:authorize>
		</c:if>
	</div>
</form:form>
